﻿using IMark.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.UC
{
    public partial class MenuLoaiSPCtrl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                List<LOAI_SAN_PHAM> ltLoaiSP = LoaiSanPhamModels.LayLoaiSanPham();
                ulMenuVertical.InnerHtml = GenSource(ltLoaiSP);
            }
            
        }

        private string GenSource(List<LOAI_SAN_PHAM> ltLoaiSP)
        {
            StringBuilder html = new StringBuilder();
            for (var i = 0; i < ltLoaiSP.Count; i++) {
                if (ltLoaiSP[i].MaLoaiCha == 0)
                {
                    int Count = 0;
                    html.Append("<li class='liCha'><a href='SanPham.aspx?IDLoaiSP=" + ltLoaiSP[i].ID + "'><i class='fa fa-male'></i><span>" + ltLoaiSP[i].TenLoai + "</span>");
                    html.Append("<i class='fa fa-angle-right'></i></a>");
                    html.Append("<div class='dropdown-menu'>");
                    html.Append("<div class='content'>");
                    html.Append("<div class='row'>");

                    for (var j = 0; j < ltLoaiSP.Count; j++) {
                        if (ltLoaiSP[i].ID == ltLoaiSP[j].MaLoaiCha) {
                            if (Count < 3)
                            {
                                Count++;
                                html.Append("<div class='col-md-4'>");
                                html.Append("<a class='menu-title' href='SanPham.aspx?IDLoaiSP=" + ltLoaiSP[j].ID + "'>" + ltLoaiSP[j].TenLoai + "</a>");
                                html.Append("<ul>");
                                for (var k = 0; k < ltLoaiSP.Count; k++) {
                                    if (ltLoaiSP[j].ID == ltLoaiSP[k].MaLoaiCha) {
                                        html.Append("<li><a href='SanPham.aspx?IDLoaiSP=" + ltLoaiSP[k].ID + "'>" + ltLoaiSP[k].TenLoai + "</a></li>");
                                    }
                                }
                                html.Append("</ul>");
                                html.Append("</div>");
                            }
                        }
                    }
                }   
            }
            html.Append("</div>");
            html.Append("</li>");
            return html.ToString();
        }
    }
}